package com.dule.Medic.pages;

import org.apache.tapestry5.annotations.CleanupRender;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property; 
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject; 

import com.dule.Medic.beans.DoctorBean;
import com.dule.Medic.model.Doctor;
import com.dule.Medic.service.DoctorService;

public class FirstPage 
{
	
	@SessionState
	@Property
	private Doctor doctor;        
	private boolean doctorExists;
	
	@SuppressWarnings("unused")
	@Property           
	@Persist         
	private String message;   
	
	@Inject      
	private DoctorService doctorService; 
	
	@Property      
	@Persist          
	private Doctor doctorBean;     
	
	public Object onActivate()
    {                  
    	if (doctorExists) 
    	{    
    		return Index.class;               
    	}   
    	doctorBean=new DoctorBean(); 
    	return null;
    }    
	
	@OnEvent(component="doctorlogin")       
	Object onLogin()
	{                  
		message=null;            
		Doctor registredDoctor=doctorService.retrive(doctorBean);   
		if(registredDoctor!= null)
		{                  
			doctor=registredDoctor;  
			doctor.getMedEntries().size();
			return Index.class;  
		} 
		else
		{ 
			message="Incorrect username or password!";  
			return this; 
		} 
		        
	}                    
	
	@CleanupRender             
	public void cleanUp(){          
		message =null;          
		}  
}
